package com.solution.framework.dao;


import com.solution.framework.model.BaseBean;
import com.solution.framework.util.Pagination;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Busline: sunguangzhu
 * Date: 13-6-18
 * Time: 下午1:19
 * To change this template use File | Settings | File Templates.
 * 封装基本操作数据库的方法
 * 增删改查
 */

public interface BaseDao<T extends BaseBean> {

    public void save(T entity);

    public void update(T entity);

    public void delete(T entity);

    public void delete(Serializable id);

    public Integer deleteAll();

    public T get(Serializable id);

    public List<T> listByHql();

    public List<T> listByHql(String hql, Object... params);

    public List<T> pageList(Pagination pagination);

    public List<T> pageList(String hql, Pagination pagination, Object... params);

    public int getTotal(final String hql, Object... params);

    //batch update
    public Collection<T> batchUpdate(Collection<T> entitys);

    public Collection<T> batchSave(Collection<T> entitys);

    //hql
    public List<Map<String, Object>> findListMapByHql(String hql);

    //special mothod
    public Map<Long, Integer> getLazyObjectsCountMap(List<Long> entityIds, String parentClassName, String ChildClassName);
    //---------------------------------------------
    public int delete(String ids);

    public Map<String, Object> findUniqueMapBySql(String sql, final Object... params);

    public List<Map<String, Object>> findListMapBySql(String sql);

    //---------------------------------------------
    public List<T> listByCriteria(Criterion... criterions);
    public List<T> listByCriteria(Order order,Criterion... criterions);
    public List<T> listByCriteria(Pagination pagination,Order order,Criterion... criterions);
    public List<T> listByCriteria(Pagination pagination,Criterion... criterions);
    public int getTotalByCriteria(Order order,Criterion... criterions);
    public int getTotalByCriteria(Criterion... criterions);


    public List<T> listByCriteria(List<Criterion> criterions);
    public List<T> listByCriteria(Order order,List<Criterion> criterions);
    public List<T> listByCriteria(Pagination pagination,Order order,List<Criterion> criterions);
    public List<T> listByCriteria(Pagination pagination,List<Criterion> criterions);
    public int getTotalByCriteria(Order order,List<Criterion> criterions);
    public int getTotalByCriteria(List<Criterion> criterions);

    public T findUniqueObjectByHql(String hql,Object...params);
}
